<template>
	<view>
		<view class="search_area">
			<u-search placeholder="搜索" :showAction="false" bgColor="#EEF4FA" v-model="policyForm.projectName"
				@change="search()" @clear="clear"></u-search>
		</view>
		<view class="bg-white">
			<u-tabs @click="clickTab" :list="list1" lineWidth="30" lineColor="#3389FF" :activeStyle="{
			            color: '#3389FF',
			            fontWeight: 'bold',
			            transform: 'scale(1.05)'
			        }" :inactiveStyle="{
			            color: '#606266',
			            transform: 'scale(1)'
			        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;">
			</u-tabs>
		</view>
		<view class="padding">
			<allList :listData='dataList' :entryStatus="0" @choosed="choosed" :isChoose="true"></allList>
		</view>
		<u-back-top :scroll-top="scrollTop"></u-back-top>
		<u-loadmore v-show="dataList.length>0" :status="status" />
	</view>
</template>

<script>
	import {
		listProjectInfo,
	} from '@/utils/api.js'
	export default {
		data() {
			return {
				policyForm: {
					pageNum: 1,
					pageSize: 10,
					state: 0,
					entryStatus: null,
					projectName: null
				},
				list1: [{
					name: '全部',
					state: 0
				}, {
					name: '签约库',
					state: 1
				}, {
					name: '在批库',
					state: 2
				}, {
					name: '在建库',
					state: 3
				}, {
					name: '竣工库',
					state: 4
				}, {
					name: '投产库',
					state: 5
				}, {
					name: '达效库',
					state: 6
				}],
				status: 'nomore',
				total: 0,
				dataList: [],
				scrollTop: 0
			}
		},
		onLoad() {
			this.init()
		},
		onReachBottom() {
			if (this.policyForm.pageNum >= this.total / 10) {
				this.status = 'nomore'
				return
			} else {
				this.status = 'loading'
				this.policyForm.pageNum++
				this.init()
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		methods: {
			init() {
				uni.showLoading({
					title: '加载中'
				});
				listProjectInfo(this.policyForm).then(response => {
					if (response.code == 200) {
						uni.hideLoading();
						this.dataList = [...this.dataList, ...response.rows]
						this.total = response.total
					} else {
						uni.hideLoading();
						uni.showToast({
							title: response.msg,
							icon: 'none',
							duration: 3000
						})
					}
					this.status = 'nomore'
				});
			},
			choosed(item) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确认选择项目：' + item.projectName + '?',
					confirmText: '确定',
					success(res) {
						if (res.confirm) {
							uni.showToast({
								title: '确认成功',
								icon: 'success',
								duration: 1000
							})
							setTimeout(() => {
								let pages = getCurrentPages();
								let prevPage = pages[pages.length - 2]; //上一个页面
								prevPage.$vm.getProjectId(item.baseId); //重点$vm
								uni.navigateBack();
							}, 1000)
						}
					}
				})
			},
			clickTab(item) {
				this.policyForm.entryStatus = item.state != 0 ? item.state : null
				this.policyForm.pageNum = 1
				this.dataList = []
				this.init()
			},
			search() {
				this.policyForm.pageNum = 1
				this.dataList = []
				this.init()
			},
			clear() {
				this.policyForm.projectName = ""
				this.search()
			}
		}
	}
</script>
<style>
	.search_area {
		padding: 10rpx 24rpx;
		background: #FFFFFF;
	}
</style>